" 使用vim特性
set nocompatible

" 设置菜单和工具栏
" set guioptions-=m
set guioptions-=T

" 设置代码折叠
set foldmethod=marker

" 设置颜色
set t_Co=256
" 设置配色方案
colorscheme darkblack

" 运行文件类型插件
filetype on
filetype plugin on
filetype plugin indent on

" 允许当前缓冲区不保存就转到后台
set hidden

" 不显示按Enter执行消息
"set shortmess=atI

" 自动读取文件当文件被外部程序改变时
set autoread

" 快速插入时间, 按 \t 
nnoremap <F7> a<C-R>=strftime("%Y/%m/%d %T")<CR><Esc>
inoremap <F7> <C-R>=strftime("%Y/%m/%d %T")<CR>

" 设置文件格式
set ffs=unix,dos

" 设置帮助语言为中文
set helplang=en
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,gbk

" 解决菜单乱码
set langmenu=en_US
let $LANG ='en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

" 编程相关设置
" 语法高亮
syntax on

" 显示行号, 列号
set number
set ruler

" 退格键能够删除空行、缩进等
set backspace=indent,eol,start

" C语言缩进
set cindent

" 设置softtab键
set expandtab
set tabstop=2
set shiftwidth=2

" 设置自动折行和行宽
set textwidth=70
set wrap 
set wrapmargin=2

" 设置taglist插件 <Leader>即 \ 键
let Tlist_Exit_Onlywindows=1
" let Tlist_Use_Right_Window=1
let Tlist_File_Fold_Auto_Close=1
let Tlist_Show_One_File=1
let Tlist_GainFocus_On_ToggleOpen=1
let Tlist_Sort_Type="name"
let Tlist_Auto_Update = 1

" 设置taglist插件
nnoremap <Leader>ta :TlistToggle<cr>
nnoremap <Leader>to :TlistOpen<cr>
inoremap <Leader>tt <Esc>:TlistToggle<cr>
inoremap <Leader>to <Esc>:TlistOpen<cr>

" 设置WinManager插件
map <Leader>wf :FirstExplorerWindow<cr>
map <Leader>wb :BottomExplorerWindow<cr>
map <Leader>wt :WMToggle<cr> 

" 设置NERDTree插件
map <Leader>nt :NERDTree<cr>

" OmniCppComplete配置
set completeopt=longest,menu      " I really HATE the preview window!!!
let OmniCpp_NameSpaceSearch=1     " 0: namespaces disabled
                                  " 1: search namespaces in the current buffer [default]
                                  " 2: search namespaces in the current buffer and in included files
let OmniCpp_GlobalScopeSearch=1   " 0: disabled 1:enabled
let OmniCpp_ShowAccess=1          " 1: show access
let OmniCpp_ShowPrototypeInAbbr=1 " 1: display prototype in abbreviation
let OmniCpp_MayCompleteArrow=1    " autocomplete after ->
let OmniCpp_MayCompleteDot=1      " autocomplete after .
let OmniCpp_MayCompleteScope=1    " autocomplete after ::

let OmniCpp_DefaultNamespaces=["std", "_GLIBCXX_STD"]

autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType c set omnifunc=ccomplete#Complete

" SuperTab设置
let g:SuperTabDefaultCompletionType = "context"

" protobuf设置
augroup filetype
  au! BufRead,BufNewFile *.proto set filetype=proto
augroup end

" thrift设置
au BufRead,BufNewFile *.thrift set filetype=thrift
if has('win32')
  au! Syntax thrift source $VIM/vimfiles/syntax/thrift.vim
else
  au! Syntax thrift source $HOME/.vim/syntax/thrift.vim
endif


map <C-F12> :!ctags -R --c++-kinds=+plx --fields=+iaS --extra=+q .<CR><CR>

" 设定默认的tags文件
if has('win32')
  au GUIEnter * simalt ~x
  set tags=tags,$VIM/vimfiles/tags
else
  au GUIEnter * call MaximizeWindow()
  set tags=tags,$HOME/.vim/tags
endif

function! MaximizeWindow()
  silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
endfunction

